/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller.admin;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.sesame.domain.Admin;
import com.sesame.domain.User;
import com.sesame.service.AdminService;
import com.sesame.service.UserService;

/**
 * @author voidman
 * 
 */
public class AdminLoginController extends SimpleFormController {

    private AdminService adminService;

    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    protected ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {
        Admin admin = (Admin) command;

        Map model = errors.getModel();
        model.put("admin", admin);

        boolean isLogin = adminService.isLogin(request, admin.getUserName(),
                admin.getPassword(), model);

        if (isLogin) {
            return new ModelAndView("redirect:adminIndex.html");
        } else {
            return new ModelAndView(getFormView(), model);
        }

    }
}